<template>
    <div></div>
</template>

<script>
import { Toast } from 'vant';
export default {
    props: {
        callback: {
            type: Function,
            default: function(){}
        }
    },
    data() {
        return {};
    },
    created(){
        this.wxReadyInit();
    },
    methods: {
        wxReadyInit() {
            let that = this;
            Toast.loading({ message: "加载中...", forbidClick: true });
            this.$http.post(this.$API.GET_SIGN_PACKAGE, { url: window.location.href.split('#')[0] })
                .then((res) => {
                    console.log('公众号js绑定', res);
                    Toast.clear();
                    if (res.code == 1) {
                        this.$WX.config({
                            debug: false,
                            appId: res.data.appId,
                            timestamp: res.data.timestamp,
                            nonceStr: res.data.nonceStr,
                            signature: res.data.signature,
                            jsApiList: [
                                'onMenuShareAppMessage',
                                'onMenuShareTimeline',
                                'chooseImage',
                                'previewImage',
                                'chooseWXPay',
                                'getLocation',
                                'getLocalImgData'
                            ]
                        });
                    } else {
                        Toast.fail(res.msg);
                    }
                })
                .catch((err) => {
                    Toast.clear();
                    console.log('公众号js绑定错误',err)
                });

            this.$WX.ready(function () {
                console.log('微信网页配置成功')
                that.callback();
            });
            this.$WX.error(function (e) {
                console.log('公众号js绑定错误',e)
            });
        },
    },
};
</script>

<style lang="less">
.not-find-content {
    padding-top: 6%;
    display: flex;
    justify-content: center;
}

.custom-image {
    width: 500px;
    height: auto;
}
</style>